package com.example.app.service;

import com.example.app.entity.FriendRequest;
import com.example.app.entity.User;
import com.example.app.mapper.FriendRequestMapper;
import com.example.app.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class FriendService {
    // implement friend logic: send request, accept, list friends
    @Resource
    private FriendRequestMapper friendRequestMapper;
    @Resource
    private UserMapper userMapper;

    public List<User> getFriends(Long userId) {
        List<Long> friendIds = friendRequestMapper.findFriendIds(userId);
        List<User> users = Collections.emptyList();
        if (friendIds != null && !friendIds.isEmpty()) {
            users = userMapper.findByUserIds(friendIds);
        }
        return users;
    }

    public FriendRequest insertFriendRequest(FriendRequest friendRequest) {
        friendRequestMapper.insertFriendRequest(friendRequest);
        return friendRequest;
    }

    public List<FriendRequest> findFriendRequest(Long toUserId, String status) {
        return friendRequestMapper.findByToUserIdAndStatus(toUserId, status);
    }

    public List<Long> getFriendIds(Long userId) {
        return friendRequestMapper.findFriendIds(userId);
    }
}
